package cn.tedu._02notice.controller;

import cn.tedu._02notice.base.response.JsonResult;
import cn.tedu._02notice.mapper.NoticeMapper;
import cn.tedu._02notice.pojo.dto.AddNoticeParam;
import cn.tedu._02notice.pojo.dto.SelectNoticeQuery;
import cn.tedu._02notice.pojo.dto.UserLoginParam;
import cn.tedu._02notice.pojo.entity.Notice;
import cn.tedu._02notice.pojo.vo.NoticeListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class NoticeController {
    @Autowired
    NoticeMapper noticeMapper;


    @PostMapping("/v1/notice/add")
    @ResponseBody
    public JsonResult add(AddNoticeParam addNoticeParam)
    {
        Notice notice = new Notice();
        /*
        notice.setContent(addNoticeParam.getContent());
        notice.setStatus(addNoticeParam.getStatus());
        notice.setTitle(addNoticeParam.getTitle());
        notice.setType(addNoticeParam.getType());
        =========
         */
        // 将第一个参数的内容复制到notice
        BeanUtils.copyProperties(addNoticeParam,notice);
        notice.setUserId(1L);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        int insert = noticeMapper.insert(notice);
        if (insert > 0)
            return new JsonResult(2000,"successfully",null);
        return new JsonResult(2001,"failed",null);
    }


/*
    @GetMapping("/v1/notice/list/{title}/{type}")
    @ResponseBody
    public List<NoticeListVO> select(SelectNoticeQuery selectNoticeQuery)
    {
        System.out.println(selectNoticeQuery);
        System.out.println(noticeMapper.selectNotice(selectNoticeQuery.getTitle(),selectNoticeQuery.getType()));
        return noticeMapper.selectNotice(selectNoticeQuery.getTitle(),selectNoticeQuery.getType());
    }
 */
    @PostMapping("v1/user/login")
    @ResponseBody
    public String login(UserLoginParam userLoginParam)
    {
        System.out.println(userLoginParam);
        return "........";
    }







}
